package com.group.elmboot.controller;

import java.util.List;

import com.group.elmboot.feign.FoodFeignClient;
import com.group.elmboot.po.Business;
import com.group.elmboot.po.Food;
import com.group.elmboot.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RefreshScope//开启动态刷新
@RestController
@RequestMapping("/BusinessController")
public class BusinessController {
	
	@Autowired
	private BusinessService businessService;
	@Qualifier("com.group.elmboot.feign.FoodFeignClient")
	@Autowired
	private FoodFeignClient foodFeignClient;
	
	@RequestMapping("/listBusinessByOrderTypeId")
	public List<Business> listBusinessByOrderTypeId(Business business) {
		return businessService.listBusinessByOrderTypeId(business.getOrderTypeId());
	}

	@RequestMapping("/getBusinessById")
	public Business getBusinessById(Business business){
		Business retBusiness = businessService.getBusinessById(business.getBusinessId());
		//在商家微服务中调用食品微服务
		List<Food> result = foodFeignClient.listFoodByBusinessId(business.getBusinessId());
		retBusiness.setFoodList(result);
		return retBusiness;
	}
	
	@RequestMapping("/getBusinessOrderBySalesDesc")
	public List<Business> getBusinessOrderBySalesDesc() {
		return businessService.getBusinessOrderBySalesDesc();
	}
	
	@RequestMapping("/updateBusinessInfo")
	public int updateBusinessInfo(Business business) {
		return businessService.updateBusinessInfo(business);
	}
	
	@RequestMapping("/insertBusinessInfo")
	public int insertBusinessInfo(Business business) {
		return businessService.insertBusinessInfo(business);
	}
	
	@RequestMapping("/listBusinessByManagerId")
	public List<Business> listBusinessByManagerId(Business business) {
		return businessService.listBusinessByManagerId(business.getManager());
	}
	
	@RequestMapping("/deleteBusinessById")
	public int deleteBusinessById(Business business) {
		return businessService.deleteBusinessById(business.getBusinessId());
	}
	
	@RequestMapping("/listBusinessByConditions")
	public List<Business> listBusinessByConditions(Business business){
		return businessService.listBusinessByConditions(business);
	}
	
	@RequestMapping("/checkBusinessNameDuplicate")
	public int checkBusinessNameDuplicate(Business business){
		return businessService.checkBusinessNameDuplicate(business);
	}
	
	@RequestMapping("/searching")
	public List<Business> searching(Business business){
		return businessService.searching(business.getBusinessName());
	}

}
